package com.tbi.graphcolouring.testers;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class StatisticsPanel extends JPanel{
	ArrayList<Integer> randomCounter = new ArrayList<>();
	int maximumCount;
	int populationSize;
	
	public StatisticsPanel(Map<Integer, Integer> randomCounter) {
		for(Entry<Integer, Integer> entry : randomCounter.entrySet()){
			if(entry.getValue() > maximumCount){
				maximumCount = entry.getValue();
			}
			this.randomCounter.add(entry.getValue());
		}
		populationSize = randomCounter.size();
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		float scale = (float)getHeight()/(float)maximumCount;
		
		for(int i=0; i<getWidth(); i++){
			g.drawLine(i, getHeight(), i,
					getHeight()-(int)((i < populationSize ? randomCounter.get(i) : 0)*scale)
				);
			g.setColor(Color.BLUE);
			if(i%100 == 0){
				g.drawLine(i, 0, i, getHeight());
				g.drawString(i+"", i, 50);
			}
			g.setColor(Color.BLACK);
		}
		
	}

}
